Resolve frontend CI failures from react-hooks/set-state-in-effect across data-loading pages - #344
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/bg-playground/BGSTM/sessions/fe25a07f-7ebb-4f80-b11b-a66e7360e274 Co-authored-by: bg-playground <259109604+bg-playground@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix react-hooks/set-state-in-effect ESLint errors
Resolve frontend CI failures from May 10, 2026
react-hooks/set-state-in-effect across data-loading pages
bg-playground
marked this pull request as ready for review
May 10, 2026 00:15
4 tasks
This was referenced May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After the
eslint-plugin-react-hooksbump, Frontend CI started failing on 11react-hooks/set-state-in-effectviolations. The failures came from effects synchronously invoking callbacks that perform immediatesetState(e.g.,setLoading(true)), plus one direct state update inside an effect.Scope of fix (11 violations / 8 files)
AuditLogPage.tsx(3)ManualLinksPage.tsx(1)MetricsDashboardPage.tsx(1)RequirementsPage.tsx(1)SuggestionDashboard.tsx(2)TestCasesPage.tsx(1)TraceabilityMatrixPage.tsx(1)UserManagementPage.tsx(1)Effect refactor pattern
loadData()/loadUsers()/loadEntries(page)with inline async IIFEs invoked viavoid, keeping behavior the same while avoiding synchronous setState in effect bodies.Direct state update in effect
SuggestionDashboard, changed top-levelsetFocusedIndex(-1)inuseEffectto microtask scheduling so the effect body itself is not synchronously mutating state.Original prompt
Problem
The Frontend CI workflow is failing due to 11
react-hooks/set-state-in-effectESLint errors introduced after bumpingeslint-plugin-react-hooksin PR #340. The rule fires whensetStateis called synchronously within auseEffectbody — including via functions that themselves callsetStatesynchronously (e.g.setLoading(true)as the first line of auseCallback).The failing job log (
.github/workflows/frontend-ci.yml) shows:Root Cause
The pattern used across all these pages looks like:
The linter traces through
loadData()and sees that it synchronously callssetLoading(true)(before anyawait), flagging it as "setState called synchronously within an effect."For
SuggestionDashboard.tsxthere is also a directsetFocusedIndex(-1)call at the top level of auseEffect.Required Fix
Fix all 11 violations across the 8 files. The preferred approach (in order of preference):
Restructure
useEffectto define an inline async function and call it, e.g.:This makes the effect body itself non-synchronous (no top-level setState call), which satisfies the rule.
Or use
voidoperator if that satisfies the installed version of the rule:For direct setState calls (like
setFocusedIndex(-1)inSuggestionDashboard), wrap in a microtask or usequeueMicrotask/setTimeout(fn, 0)— or use an inline async IIFE. Alternatively, if the functional pattern is clearly intentional and idiomatic React, a targeted// eslint-disable-next-line react-hooks/set-state-in-effectis acceptable as a last resort for that specific line.Do NOT use blanket
eslint-disablefile-level comments. Fix each violation precisely.Files to Fix
frontend/src/pages/AuditLogPage.tsx— 3 errors (lines ~105, ~109, ~128)frontend/src/pages/ManualLinksPage.tsx— 1 error (line ~44)frontend/src/pages/MetricsDashboardPage.tsx— 1 error (line ~26)frontend/src/pages/RequirementsPage.tsx— 1 error (line ~45)frontend/src/pages/SuggestionDashboard.tsx— 2 errors (lines ~171, ~176)frontend/src/pages/TestCasesPage.tsx— 1 error (line ~46)frontend/src/pages/TraceabilityMatrixPage.tsx— 1 error (line ~26)frontend/src/pages/UserManagementPage.tsx— 1 error (line ~57)Acceptance Criteria
npm run lintpasses with 0 errors in the frontend directoryeslint-disablecomments added at file levelmainbranchThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: yes, please. Thank you!
Assistant: Good news and a time-saver:
state_reason: completed). Nothing to do there.Assistant: Good news on both:
This pull request was created from Copilot chat.